#include "comm.hpp"
int main()
{
    Init init;
    int shmid=CreatSHM();//创建共享内存
    //sleep(2);
    char *shmptr=(char*)shmat(shmid,NULL,0);//关联
    int fd=open(FIFOFILE_NAME,O_RDONLY);//打开管道文件
    //通信代码
    while(true)
    {
        char c;
        ssize_t n=read(fd,&c,1);//读取管道文件
        if(n<0)break;
        else if(n==0)break;
        else
        //只有读到才会往后执行
        printf("Process B say@ %s\n",shmptr);
        sleep(1);
    }

   // sleep(10);
    int n=shmdt(shmptr);//取消关联
    if(n==-1)
    {
        perror("shmdt");
        exit(-3);
    }
    //获取属性并打印
    struct shmid_ds shmds;
    shmctl(shmid,IPC_STAT,&shmds);
    std::cout<<"atime:"<<shmds.shm_atime<<" "<<"nattch:"<<shmds.shm_nattch<<" "<<std::endl;

    //释放共享内存
    //sleep(1);
    shmctl(shmid,IPC_RMID,NULL);
    close(fd);
    return 0;
}